<?php
/**
 * Created by PhpStorm.
 * User: aa
 * Date: 2019/9/4
 * Time: 15:22
 */

/**
 * 获取url
 *
 * @param $name url别名
 * @param array $param 参数数组
 * @return bool|mixed|null|string|string[]
 */
function url($name, $param = []) {
    $route = require APP_PATH . 'config/route.php';
    if(is_array($route) && count($route)>0){
        foreach ($route as $key => $value) {
            $end  = array_pop($value);
            $end2 = array_pop($value);
            if($name == $end2) {
               foreach ($param as $k => $v) {
                   $end = preg_replace("/\($k\)/", $v, $end);
               }
               return $end;
            }
        }
    }
    return false;
}

/**
 * 获取配置信息
 *
 * @param $key 配置的键 支持  二维数组  user.age
 * @return string
 */
function config($key) {
    $config = require APP_PATH . 'config/config.php';
    $arr = explode('.', $key);
    if(is_array($arr) && count($arr) && isset($arr[1]) && $arr[1]) {
        return $config[$arr[0]][$arr[1]] ?? '';
    } else {
        return $config[$key] ?? '';
    }

}

function captcha($width=60, $height=30) {
    include_once APP_PATH.'system/controller/Captcha.class.php';
    Captcha::crate($width,$height);
}